package com.xha.springcloud.service.impl;

import cn.hutool.core.util.IdUtil;
import com.xha.springcloud.service.IMessageProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class IMessageProviderImpl implements IMessageProvider {

    @Resource
    private StreamBridge streamBridge;

    @Override
    public String send() {
        String uuid = IdUtil.simpleUUID();
        //这里说明一下这个 streamBridge.send 方法的参数 第一个参数是exchange或者topic 就是主题名称(bindingName)
        //默认的主题名称是通过
        //输入:    <方法名> + -in- + <index>
        //输出:    <方法名> + -out- + <index>
        //这里我们接收的时候就要用send方法 参数是consumer<String>接收  详情看8802的controller
        //consumer的参数类型是这里message的类型
        streamBridge.send("send-in-0",uuid);
        System.out.println("******uuid：" + uuid);
        return null;
    }
}
